﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class Favorite_ListController : UserController
    {
        public IFavoriteService _favorite { get; set; }
        [Authorize]
        [HttpGet]
        public IActionResult Get()
        {
            var user = GetUserInfo();
            if (user == null)
            {
                return Ok(new { status = 0, msg = "请先登录！" });
            }
            var list = _favorite.GetList(1, 1000, "where user_id=" + user.id, "id desc");
            var sys = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            for (int i = 0; i < list.Count; i++)
            {
                list[i].img_url = sys.weburl + list[i].img_url;
            }
            return Ok(new { status = 1, list = list });
        }
    }
}